package com.lz.football.module.main.view
{
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.MainEvent;
	import com.liangzhong.events.NotifierEvent;
	import com.liangzhong.events.TaskEvent;
	import com.lz.football.module.base.IComponent;
	
	import common.BaseView.DisplayMouseEventManager;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 *右边面板 
	 * @author lake
	 * 
	 */	
	public class RightPanel extends Sprite implements IComponent
	{
		/**
		 *皮肤 
		 */		
		public var symbolSkin			:MovieClip;
		/**
		 *邮箱mc 
		 */		
		public static var mailMc		:MovieClip;
		/**
		 * 邮箱按钮
		 */		
		public var mailBtn				:SimpleButton;
		/**
		 *邮件未读数 
		 */		
		public var txtMailNum			:TextField;
		/**
		 *好友mc 
		 */		
		public static var friendMc		:MovieClip;
		/**
		 *好友按钮 
		 */
		public var friendBtn:SimpleButton;
		
		/**
		 *好友数量 
		 */
		public var friendNum:TextField;
		/**
		 *国家任务
		 */		
		public var competeBtn 		:SimpleButton;
		/**
		 *排行榜 
		 */		
		public var rankBtn			:SimpleButton;
		/**
		 *设置按钮 
		 */		
		public var settingBtn		:SimpleButton;
		/**
		 *按钮顺序  上下 
		 */		
		private static var btns	:Array;
		/**
		 *对应初始坐标  上下 
		 */		
		private static var xyArr	:Array;
		
		public function RightPanel()
		{
			super();
		}
		/**
		 *初始化 
		 * @param view
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
			mailMc = symbolSkin.mailMc;
			mailBtn = symbolSkin.mailMc.mailBtn;
			symbolSkin.mailMc.infoMc.mouseChildren = false;
			symbolSkin.mailMc.infoMc.mouseEnabled = false;
			txtMailNum = symbolSkin.mailMc.infoMc.txtNum;
			txtMailNum.text = "0";
			friendMc = symbolSkin.friendMc;
			friendBtn =  symbolSkin.friendMc.friendBtn;
			friendNum = symbolSkin.friendMc.friendInfo.txtNum;
			symbolSkin.friendMc.friendInfo.mouseChildren = false;
			symbolSkin.friendMc.friendInfo.mouseEnabled = false;
			friendNum.text = "0" + "";
			competeBtn = symbolSkin.competeBtn;
			rankBtn = symbolSkin.rankBtn;
			settingBtn = symbolSkin.settingBtn;
			//rankBtn.visible = false;
			var tipsInfo :String = "";
			tipsInfo = "国家任务";
			DisplayMouseEventManager.instance.addTipsDisplay(competeBtn,tipsInfo);
			tipsInfo = "邮件";
			DisplayMouseEventManager.instance.addTipsDisplay(mailBtn,tipsInfo);
			tipsInfo = "好友";
			DisplayMouseEventManager.instance.addTipsDisplay(friendBtn,tipsInfo);
			tipsInfo = "排行榜";
			DisplayMouseEventManager.instance.addTipsDisplay(rankBtn,tipsInfo);
			addEvtListener();
			
			btns = [mailMc,friendMc,competeBtn,rankBtn,settingBtn];
			xyArr = [];
			xyArr.push({x:mailMc.x,y:mailMc.y});
			xyArr.push({x:friendMc.x,y:friendMc.y});
			xyArr.push({x:competeBtn.x,y:competeBtn.y});
			xyArr.push({x:rankBtn.x,y:rankBtn.y});
			xyArr.push({x:settingBtn.x,y:settingBtn.y});
		}
		/**
		 *添加事件 
		 * 
		 */		
		public function addEvtListener():void
		{
			mailBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			friendBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			competeBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			rankBtn.addEventListener(MouseEvent.CLICK,clickHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.MAIL_NUM_CHANGE,mailNumHandler);
			AppEventDispatcher.getInstance().addEventListener(NotifierEvent.FRIEND_DATA_CHANGE,friendNumHandler);
		}
		
		/**
		 *申请好友的数量 
		 * @param event
		 * 
		 */
		protected function friendNumHandler(event:NotifierEvent):void
		{
			friendNum.text = "" + event.params;
		}
		/**
		 *未领取邮件改变 
		 * @param e
		 * 
		 */		
		private function mailNumHandler(e :NotifierEvent):void
		{
			txtMailNum.text = "" + e.params;
		}
		/**
		 *点击事件 
		 * @param e
		 * 
		 */		
		private function clickHandler(e :MouseEvent):void
		{
			switch(e.target)
			{
				case mailBtn://邮箱
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.Open_Mail_View));
					break;
				}
				case friendBtn://好友
				{
					AppEventDispatcher.getInstance().dispatchEvent(new MainEvent(MainEvent.OPEN_FRIEND_VIEW));
					break;
				}
				case competeBtn://国家任务
				{
					AppEventDispatcher.getInstance().dispatchEvent(new TaskEvent(MainEvent.OPEN_NATION_TASK));
					break;
				}
				case rankBtn://排行榜
				{
					AppEventDispatcher.getInstance().dispatchEvent(new TaskEvent(MainEvent.OPEN_RANK_LIST));
					break;
				}
			}
		}
		/**
		 *重设按钮位置 
		 */		
		public static function resizeBtnPos():void
		{
			var tbtn :DisplayObject;
			var j :int;
			for(var i :int = 0;i < btns.length;i++)
			{
				tbtn = btns[i];
				if(tbtn.visible)
				{
					tbtn.y = xyArr[j].y;
					j ++;
				}
			}
		}
		/**
		 *删除事件 
		 * 
		 */		
		public function removeEvtListener():void
		{
		}
		/**
		 *销毁 
		 */		
		public function destroyView():void
		{
		}
	}
}